AddCSLuaFile( "init.lua" )

local SolidWhite = CreateMaterial( "SolidWhite_z", "UnlitGeneric", {
    ["$basetexture"] = "color/white",
    ["$vertexcolor"] = "1",
    ["$vertexalpha"] = "1",
    ["$nolod"] = "1",
} )

local Glow = Material( "sprites/physg_glow1" )
function EFFECT:Init( data )
	self.Entity.Die = CurTime() + 3
	self.Entity.Pos = data:GetStart()
	self.Entity.End = data:GetOrigin()
	self.Entity.Normal = ( self.Entity.End - self.Entity.Pos ):GetNormal()
	self.Entity.Start = CurTime()
	self.Entity.Dist = self.Entity.Pos:Distance( self.Entity.End )
	self.Entity.CurPos = self.Entity.Pos
	
	self.Entity.MuzzleDie = CurTime() + 0.05
	
end

function EFFECT:Think( )

	if CurTime() > self.Die or self.Entity.CurPos:Distance( self.Entity.Pos ) > self.Entity.Dist then
		local trRes = util.TraceLine( { start = self.Entity.CurPos-self.Entity.Normal*10, endpos = self.Entity.CurPos+self.Entity.Normal*10 } )
		local sparks = EffectData()
		sparks:SetOrigin( trRes.HitPos )
		sparks:SetNormal( trRes.HitNormal*-1 )
		sparks:SetMagnitude( 0.2 )
		sparks:SetScale( 1 )
		sparks:SetRadius( 0.5 )
		util.Effect( "AR2Impact", sparks )
		util.Effect( "Sparks", sparks )
		return false
	end
	
	return true
end

function EFFECT:Render()

	local ent_pos = self.Entity.Pos + self.Entity.Normal * ( CurTime() - self.Entity.Start ) * 800
	
	render.SetMaterial( Glow )
	render.DrawSprite( ent_pos + self.Entity.Normal*-5, 15, 15, Color( 255, 255, 255, 15 ) )
	render.DrawSprite( ent_pos + self.Entity.Normal*-20, 50, 50, Color( 250, 139, 39, 15 ) )

	if CurTime() < self.Entity.MuzzleDie then
		local Scale = ( CurTime() - self.Entity.MuzzleDie )/0.01
		render.DrawSprite( self.Entity.Pos, 15+5*Scale, 15, Color( 250, 139, 39, 155 ) )
		render.DrawSprite( self.Entity.Pos, 8+5*Scale, 8, Color( 255, 255, 255, 255 ) )
	end

	render.SetMaterial( SolidWhite )
	render.StartBeam( 5 )
	render.AddBeam( ent_pos + self.Entity.Normal*(75-60), 0, 0, Color( 250, 139, 39, 255 ) )
	render.AddBeam( ent_pos + self.Entity.Normal*(70-60), 5, 0, Color( 255, 255, 255, 35 ) )
	render.AddBeam( ent_pos + self.Entity.Normal*(60-60), 6, 0, Color( 255, 255, 255, 35 ) )
	render.AddBeam( ent_pos + self.Entity.Normal*(40-60), 4, 0.6, Color( 250, 139, 39, 35 ) )
	render.AddBeam( ent_pos, 0.5, 1, Color( 250, 139, 39, 0 ) )
	render.EndBeam()
	
	render.StartBeam( 5 )
	render.AddBeam( ent_pos + self.Entity.Normal*(75-60), 0, 0, Color( 255, 255, 255, 255 ) )
	render.AddBeam( ent_pos + self.Entity.Normal*(70-60), 3, 0, Color( 255, 255, 255, 255 ) )
	render.AddBeam( ent_pos + self.Entity.Normal*(60-60), 3, 0, Color( 251, 201, 151, 255 ) )
	render.AddBeam( ent_pos + self.Entity.Normal*(40-60), 1, 0.6, Color( 250, 139, 39, 155 ) )
	render.AddBeam( ent_pos, 0.1, 1, Color( 250, 139, 39, 55 ) )
	render.EndBeam()
	
	self.Entity.CurPos = ent_pos
	
end
